using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
using System.Data;
namespace data
{
    public class buffer
    {
        
        private Queue<string> queue = new Queue<string>();
        public void BufferRS232()
        {
            Thread thread = new Thread(this.ReadInfoFromFile);
            StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
            Console.WriteLine("Type quit to exit");
            string message = string.Empty;
            bool _continue = true;
            while (_continue)
            {
                
                if (stringComparer.Equals("quit", message))
                {
                    _continue = false;
                    message = string.Empty; 
                }
                else
                {
                    this.ReadInfoFromFile();
                }
            }
        }
        private void ReadInfoFromFile()
         {
            string directoryPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            StreamReader streamReader = new StreamReader(string.Format("{0}\\data", directoryPath));
            string sLine = "";
            sLine = streamReader.ReadLine();
             while (sLine != null)
                {
                    
                    
                        //this.QueueOperation(string.Format("{0}-{1}",sLine,DateTime.UtcNow.ToString()));
                     Thread.Sleep(2000);
                     crud.crud.Insert(sLine, DateTime.Now.ToString());
                     sLine = streamReader.ReadLine();   
                   
                }
                streamReader.Close();
          }
        private void QueueOperation(string value)
        {
             queue.Enqueue(value);
             Console.WriteLine(queue.Dequeue());             
        }
     }
 }
